<template>
  <div class="filtrate-city">
    <el-select class="city-select" v-model="currentCityModel" size="small"
               @change="changeCity">
      <el-option
        v-for="item in cityListOption"
        :key="item.code"
        :label="item.name"
        :value="item.code"
        class="custom-select-option"
      />
    </el-select>
  </div>
</template>

<script setup>
import {defineProps, watch, ref, defineEmits} from "vue";

const props = defineProps({
  cityList: {
    type: Array,
    default: () => []
  },
  currentCity: {
    type: String,
    default: ''
  }
})

const emit = defineEmits(['changeCity'])

const currentCityModel = ref('')
const cityListOption = ref([])

watch(
  () => props?.currentCity,
  (newVal) => {
    currentCityModel.value = newVal
  },
  {immediate: true}
)

watch(
  () => props?.cityList,
  (newVal) => {
    cityListOption.value = [...newVal]
  },
  {immediate: true}
)

const changeCity = (res) => {
  emit('changeCity', res)
}
</script>

<style scoped lang="less">
.filtrate-city {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 75px;
  z-index: 1;
  display: flex;
  align-items: center;

  /deep/ .el-select__wrapper {
    background: rgba(33, 112, 207, 0.2);
    box-shadow: inset 0 0 0.04167rem 0 #3D7FFF;
    border: 0.00521rem solid #67BAEF;

    .el-select__selected-item {
      color: white;
    }
  }
}

/deep/ .el-select__wrapper {
  background: #204485;

  .el-select__selected-item {
    color: white;
  }
}

.custom-select-option {
  color: #ffffff;
  background: #1C5BCC;
}

.custom-select-option.is-selected {
  color: #00e0ff;
}

.custom-select-option:hover {
  background: #368CF2;
}
</style>